from flask.views import MethodView, View
from flask import render_template, request, jsonify

import myblog.models

class MyInfo(View):
    methods = ['GET', 'POST']

    def dispatch_request(self):
        return render_template('myinfo/mydetail.html')


class GetMessage(MethodView):
    def post(self):
        name = request.form.get('name')
        email = request.form.get('email')
        mgs = request.form.get('message')
        msg = myblog.models.Message(name, email, mgs)
        myblog.models.db.session.add(msg)
        myblog.models.db.session.commit()
        remsg = dict(name=name)
        return jsonify(remsg)
